﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HttpServer;
using System.IO;
using System.Net;
using HttpListener=WFWS.Core.HttpListener;
namespace WFWS.Test
{
    class Program
    {

        static HttpListener listener;
        static void Main(string[] args)
        {
            WFWS.Core.HttpServer server = WFWS.Core.HttpServer.Current; 
            server.Start();
            //listener = HttpListener.Create(808);
            //listener.RequestReceived += OnRequest;
            //listener.Start(50);

            while (Console.Read() != (int)'s')
            {
            }
            
            server.Stop();
        }
        
        private static void OnRequest(object source, RequestEventArgs args)
        {
            IHttpClientContext context = (IHttpClientContext)source;
            IHttpRequest request = args.Request;

            // Respond is a small convenience function that let's you send one string to the browser.
            // you can also use the Send, SendHeader and SendBody methods to have total control.
            if (request.Uri.AbsolutePath == "/hello")
                context.Respond("Hello to you too!"); 

            else if (request.UriParts.Length == 1 && request.UriParts[0] == "goodbye")
            {
            	IHttpResponse response = request.CreateResponse(context);
                StreamWriter writer = new StreamWriter(response.Body);
                writer.WriteLine("Goodbye to you too!");
                writer.Flush();
                response.Send();
            }
        }
    }
}
